<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>    
    <div id="app">      
        <p>count:{{count}}</p>
        <p>isLimit：{{isLimit}}</p>
        <input type="button" value="修改" @click="changeCount" >
    </div>
</body>
</html>

<script src="./js/vue.global.js"></script>
<script>    

     const {createApp,ref,reactive,watchEffect} = Vue;

    let app = createApp({
        setup(){

            let count = ref(1);
            let isLimit = ref(false);

            watchEffect((cb)=>{
                console.log("watchEffect：count.value",count.value);

                let myTimer = setTimeout(function(){

                    console.log("修改isLimit的值");
                    
                    isLimit.value = count.value>=10?true:false

                },2000);

                // cb里的回调函数是在下次触发副作用时，首先会执行的代码。
                cb(()=>{
                    console.log("清除定时器");
                    clearTimeout(myTimer);
                })

            });

            function changeCount(){
                count.value++;
            }

            
            return {
               count,changeCount,isLimit
            }
        }
    })

    app.mount("#app");

</script>